package com.sdhs.paas.rc.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.github.pagehelper.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;
import com.sdhs.paas.rc.bean.DocDiskBean;
import com.sdhs.paas.rc.repository.DocDiskMapper;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.github.pagehelper.PageHelper;

/**
* 描述：DocDiskService 服务接口
* @author kangjichang
* @date 2018-12-06
*/

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.rc.repository")
@Service
public class DocDiskService extends BaseDao<DocDiskBean, DocDiskMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return DocDiskMapper.class.getName();
		}
		
		@Autowired
		private DocDiskMapper docDiskMapper;
		
		public PaginationEntity<DocDiskBean> getPageDocDiskList(BasePage pageRequest, DocDiskBean docDiskBean) {
			Page<DocDiskBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true, false);
			List<DocDiskBean> list = docDiskMapper.getList(docDiskBean);
			PaginationEntity<DocDiskBean> paginationEntity = new PaginationEntity<DocDiskBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveDocDisk(DocDiskBean docDiskBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docDiskMapper.insertDocDisk(docDiskBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateDocDisk(DocDiskBean docDiskBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docDiskMapper.updateDocDisk(docDiskBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public DocDiskBean getDocDiskDetail(String id) {
			return docDiskMapper.getDocDiskDetail(id);
		}
		
		public boolean deleteDocDisk(DocDiskBean docDiskBean){
			return docDiskMapper.deleteDocDisk(docDiskBean)>0;
		}
      
}